import js from "@eslint/js";
import globals from "globals";
import pluginVue from "eslint-plugin-vue";
import pluginQuasar from "@quasar/app-vite/eslint";
import { defineConfigWithVueTs, vueTsConfigs } from "@vue/eslint-config-typescript";
import prettierSkipFormatting from "@vue/eslint-config-prettier/skip-formatting";

export default defineConfigWithVueTs(
  {
    files: ["./**/*.js", "./**/*.ts", "./**/*.vue"],
    languageOptions: {
      parser: pluginVue.parser,
      parserOptions: {
        parser: "@typescript-eslint/parser", // 直接指定TS解析器
        project: "./tsconfig.json",
        extraFileExtensions: [".vue"],
        ecmaFeatures: {
          jsx: true
        },
        sourceType: "module"
      }
    }
  },

  pluginQuasar.configs.recommended(),
  js.configs.recommended,
  pluginVue.configs["flat/essential"],
  vueTsConfigs.recommendedTypeChecked,

  {
    files: ["**/*.ts", "**/*.vue"],
    languageOptions: {
      parserOptions: {
        project: "./tsconfig.json" // 再次明确指定
      }
    },
    rules: {
      '@typescript-eslint/consistent-type-imports': ["error", { prefer: "type-imports" }],
      '@typescript-eslint/await-thenable': "error"
    }
  },

  {
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module",
      globals: {
        ...globals.browser,
        ...globals.node,
        process: "readonly",
        ga: "readonly",
        cordova: "readonly",
        Capacitor: "readonly",
        chrome: "readonly",
        browser: "readonly"
      }
    },
    rules: {
      "no-var": "error",
      "no-compare-neg-zero": "error",
      "no-eval": "error",
      "vue/multi-word-component-names": "off",
      "@typescript-eslint/no-explicit-any": "off",
      quotes: ["warn", "double", { avoidEscape: true, allowTemplateLiterals: true }],
      "@typescript-eslint/explicit-function-return-type": "off",
      "@typescript-eslint/no-var-requires": "off",
      "no-unused-vars": "off",
      "@typescript-eslint/no-unused-vars": ["error"],
      "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
    }
  },

  {
    files: ["src-pwa/custom-service-worker.ts"],
    languageOptions: {
      globals: {
        ...globals.serviceworker
      }
    }
  },

  prettierSkipFormatting
);
